package Basiques;

import java.io.Serializable;
import java.util.ArrayList;

import Persistance.TTournoi;
import PersistanceBase.PrimaryKey;
import PersistanceBase.TableGenerique;
import PersistanceBase.TableName;
import android.content.ContentValues;
import android.database.Cursor;
@TableName(Name="T_TOURNOI")
public class TTournoiBasique extends TableGenerique implements Serializable
{
	private static final long serialVersionUID = 1L;
	protected Integer buyIn;

	protected Integer classement;

	protected String libelle;

	protected Integer nbJoueurs;

	@PrimaryKey(AutoIncrement="True")
	protected Integer num;

	protected Integer stackDepart;

	protected Integer termine;


	public Integer getBuyIn()
	{
		return buyIn;
	}

	public void setBuyIn(Integer value)
	{
		buyIn = value;
	}

	public Integer getClassement()
	{
		return classement;
	}

	public void setClassement(Integer value)
	{
		classement = value;
	}

	public String getLibelle()
	{
		return libelle;
	}

	public void setLibelle(String value)
	{
		libelle = value;
	}

	public Integer getNbJoueurs()
	{
		return nbJoueurs;
	}

	public void setNbJoueurs(Integer value)
	{
		nbJoueurs = value;
	}

	public Integer getNum()
	{
		return num;
	}

	public void setNum(Integer value)
	{
		num = value;
	}

	public Integer getStackDepart()
	{
		return stackDepart;
	}

	public void setStackDepart(Integer value)
	{
		stackDepart = value;
	}

	public Integer getTermine()
	{
		return termine;
	}

	public void setTermine(Integer value)
	{
		termine = value;
	}

	@Override
	public ContentValues GetContentValues(boolean avecPrimaryKey){
		ContentValues values = new ContentValues(12);
		if (getDateCreation() != null)
			values.put("DATE_CREATION", TableGenerique.DATE_FORMAT_ISO.format(getDateCreation()));
		if (getDateModif() != null)
			values.put("DATE_MODIF", TableGenerique.DATE_FORMAT_ISO.format(getDateModif()));
		if (getBuyIn() != null)
			values.put("TRN_BUY_IN", getBuyIn());
		if (getClassement() != null)
			values.put("TRN_CLASSEMENT", getClassement());
		if (getLibelle() != null)
			values.put("TRN_LIBELLE", getLibelle());
		if (getNbJoueurs() != null)
			values.put("TRN_NB_JOUEURS", getNbJoueurs());
		if (getNum() != null)
			values.put("TRN_NUM", getNum());
		if (getStackDepart() != null)
			values.put("TRN_STACK_DEPART", getStackDepart());
		if (getTermine() != null)
			values.put("TRN_TERMINE", getTermine());
		if (getUserCreation() != null)
			values.put("USER_CREATION", getUserCreation());
		if (getUserModif() != null)
			values.put("USER_MODIF", getUserModif());
		if (getVersion() != null)
			values.put("VERSION", getVersion());
		return values;
	}

	@Override
	public String GenerationClauseWhere(boolean primaryKeyOnly)
	{
		ArrayList<String> listeMots = new ArrayList<String>(12);
		if (getNum() != null)
		{
			listeMots.add(String.format("TRN_NUM = %s ", getNum()));
		}
		if (primaryKeyOnly)
			return TableGenerique.concatWith(listeMots, " and ");
		if (getDateCreation() != null)
		{
			listeMots.add(String.format("DATE_CREATION = '%s' ", DATE_FORMAT_ISO.format(getDateCreation())));
		}
		if (getDateModif() != null)
		{
			listeMots.add(String.format("DATE_MODIF = '%s' ", DATE_FORMAT_ISO.format(getDateModif())));
		}
		if (getBuyIn() != null)
		{
			listeMots.add(String.format("TRN_BUY_IN = %s ", getBuyIn()));
		}
		if (getClassement() != null)
		{
			listeMots.add(String.format("TRN_CLASSEMENT = %s ", getClassement()));
		}
		if (getLibelle() != null)
		{
			listeMots.add(String.format("TRN_LIBELLE = '%s' ", getLibelle().replace("'", "''")));
		}
		if (getNbJoueurs() != null)
		{
			listeMots.add(String.format("TRN_NB_JOUEURS = %s ", getNbJoueurs()));
		}
		if (getStackDepart() != null)
		{
			listeMots.add(String.format("TRN_STACK_DEPART = %s ", getStackDepart()));
		}
		if (getTermine() != null)
		{
			listeMots.add(String.format("TRN_TERMINE = %s ", getTermine()));
		}
		if (getUserCreation() != null)
		{
			listeMots.add(String.format("USER_CREATION = '%s' ", getUserCreation().replace("'", "''")));
		}
		if (getUserModif() != null)
		{
			listeMots.add(String.format("USER_MODIF = '%s' ", getUserModif().replace("'", "''")));
		}
		if (getVersion() != null)
		{
			listeMots.add(String.format("VERSION = %s ", getVersion()));
		}
		return TableGenerique.concatWith(listeMots, " and ");
	}
	@Override
	public TTournoi getObjetFromDataBase(Cursor c)
	{
		TTournoi objetRetour = new TTournoi();
		int colonneIndex = 0;
		colonneIndex = c.getColumnIndex("DATE_CREATION");
		if (c.isNull(colonneIndex))
			objetRetour.DateCreation = null;
		else
			objetRetour.DateCreation = TableGenerique.dataBaseFieldToDate(colonneIndex, c);

		colonneIndex = c.getColumnIndex("DATE_MODIF");
		if (c.isNull(colonneIndex))
			objetRetour.DateModif = null;
		else
			objetRetour.DateModif = TableGenerique.dataBaseFieldToDate(colonneIndex, c);

		colonneIndex = c.getColumnIndex("TRN_BUY_IN");
		if (c.isNull(colonneIndex))
			objetRetour.setBuyIn(null);
		else
			objetRetour.setBuyIn(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("TRN_CLASSEMENT");
		if (c.isNull(colonneIndex))
			objetRetour.setClassement(null);
		else
			objetRetour.setClassement(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("TRN_LIBELLE");
		if (c.isNull(colonneIndex))
			objetRetour.setLibelle(null);
		else
			objetRetour.setLibelle(c.getString(colonneIndex));

		colonneIndex = c.getColumnIndex("TRN_NB_JOUEURS");
		if (c.isNull(colonneIndex))
			objetRetour.setNbJoueurs(null);
		else
			objetRetour.setNbJoueurs(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("TRN_NUM");
		if (c.isNull(colonneIndex))
			objetRetour.setNum(null);
		else
			objetRetour.setNum(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("TRN_STACK_DEPART");
		if (c.isNull(colonneIndex))
			objetRetour.setStackDepart(null);
		else
			objetRetour.setStackDepart(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("TRN_TERMINE");
		if (c.isNull(colonneIndex))
			objetRetour.setTermine(null);
		else
			objetRetour.setTermine(c.getInt(colonneIndex));

		colonneIndex = c.getColumnIndex("USER_CREATION");
		if (c.isNull(colonneIndex))
			objetRetour.UserCreation = null;
		else
			objetRetour.UserCreation = c.getString(colonneIndex);

		colonneIndex = c.getColumnIndex("USER_MODIF");
		if (c.isNull(colonneIndex))
			objetRetour.UserModif = null;
		else
			objetRetour.UserModif = c.getString(colonneIndex);

		colonneIndex = c.getColumnIndex("VERSION");
		if (c.isNull(colonneIndex))
			objetRetour.Version = null;
		else
			objetRetour.Version = c.getInt(colonneIndex);

		return objetRetour;
	}

}
